//
//  DECXWarehouseChargeManager.m
//  DECXInStore
//
//  Created by 李坤 on 2019/12/16.
//  Copyright © 2019 程强. All rights reserved.
//

#import "DECXWarehouseChargeManager.h"
#import "DECXChargeDetailsObj.h"
#import "NSObject+YYModel.h"
#import "DECXDriverObj.h"
#import "NSString+YYAdd.h"

@implementation DECXWarehouseChargeManager
- (DSASubject *)getOrderChargeDetails:(NSString *)oid
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:oid,@"order_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=details", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB[@"obj"];
        DECXChargeDetailsObj *chargeObj = [DECXChargeDetailsObj yy_modelWithDictionary:dic];
        [subject sendNext:chargeObj];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)createPayOrderWithUid:(NSString *)uid orderID:(NSString *)oid count:(NSString *)count driver:(NSString *)driver
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:oid,@"list_id",uid,@"user_id",count,@"num",driver,@"driver",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=orderdepot", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)addDriverWithUid:(NSString *)uid name:(NSString *)user_name phone:(NSString *)phone car_code:(NSString *)car_code card_no:(NSString *)card_no
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",user_name,@"user_name",phone,@"phone",car_code,@"car_code",card_no,@"card_no",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=driveradd", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        [subject sendNext:dic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)decxUserDriverList:(NSString *)uid
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=driver", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSArray *ary = parse.responseJsonOB[@"obj"];
        NSMutableArray *tempAry = @[].mutableCopy;
        for (NSDictionary *mdic in ary) {
            DECXDriverObj *driver = [[DECXDriverObj alloc]initWithResponse:mdic];
            [tempAry addObject:driver];
        }
        [subject sendNext:tempAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)payOrderWithOid:(NSString *)oid uid:(NSString *)uid
{
    DSASubject *subject = [DSASubject subject];
    NSString *key = [NSString stringWithFormat:@"%@%@",@"DECXiuyujkUJUSUF836344SISO9871",uid];
    key = [key md5String];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:oid,@"order_id",key,@"sgin",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=depotorderpay", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *ary = parse.responseJsonOB;
        [subject sendNext:ary];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)cancelDeliveryOrder:(NSString *)oid
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:oid,@"id",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=cancel", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSArray *ary = parse.responseJsonOB[@"obj"];
        NSMutableArray *tempAry = @[].mutableCopy;
        for (NSDictionary *mdic in ary) {
            DECXDriverObj *driver = [[DECXDriverObj alloc]initWithResponse:mdic];
            [tempAry addObject:driver];
        }
        [subject sendNext:tempAry];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
@end
